package com.ssmfuse.mapper;

import com.ssmfuse.Bean.Page;
import com.ssmfuse.domain.Question;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface QuestionMapper {
    /**
     * 添加题目
     */
    @Insert("insert into question(question_name,question_answer,question_explain) values(#{question_name},#{question_answer},#{question_explain})")
    void addQuestion(Question question);

    /**
     * 删除题目
     */
    @Delete("delete from question where id = #{id}")
    void deleteQuestion(int id);


    /**
     * 更新题目
     */
    @Update("update question set question_name=#{question_name},question_answer=#{question_answer},question_explain=#{question_explain} where id =#{id}")
    void updateQuestion(Question question);


    /**
     * 根据匹配查询题目并返回
     * like查找题目
     * 根据三个相似词数的查询
     */
    @Select("select *from question where question_name like '%${arg0}%' and question_name like '%${arg1}%'and question_name like '%${arg2}%'  ")
    List<Question> findQuestion(String questionName1,String questionName2,String questionName3);

    /**
     *  根据一个相似词进行查询
     */
    @Select("select *from question where question_name like '%${arg0}%'")
    List<Question> findQuestion_one(String questionName1);

    /**
     * 根据两个相似词进行查询
     */
    @Select("select *from question where question_name like '%${arg0}%' and question_name like '%${arg1}%'")
    List<Question> findQuestion_two(String questionName1,String questionName2);

    /**
     * 根据五个相似词进行相似查询
     */
    @Select("select *from question where question_name like '%${arg0}%' and question_name like '%${arg1}%' and question_name like '%${arg2}%' and question_name like '%${arg3}%' and question_name like '%${arg4}%'")
    List<Question> findQuestion_five(String questionName1,String questionName2,String questionName3,String questionName4,String questionName5);


    /**
     * 查找所有题目
     */
    @Select("select *from question")
    List<Question> questionList();


    /**
     * 分页查询
     */
    Page<Question> page(int pageNo, int pageSize);

    //查询记录
    @Select("select count(*) from question")
    Integer queryForPageTotal();

    //查询当前页数据
    @Select("select *from question limit #{begin},#{pageSize}")
    List<Question> queryForPageItems(@Param("begin")int begin,@Param("pageSize")int pageSize);
}
